﻿#region Imports

using System.Collections.Generic;
using NHibernate;
using Spring.Data.NHibernate;
using Spring.Data.NHibernate.Generic.Support;

#endregion

namespace d3PrtDgn.Core.BaseData
{
	/// <summary>
    /// Hibernate BaseDao DAO
	/// </summary>
    public class BaseDao : HibernateDaoSupport
	{

        /// <summary>
        /// Saves or updates BaseEntity
        /// </summary>
        /// <param name="album"></param>
        /// <returns></returns>
        public BaseEntity SaveOrUpdate(BaseEntity entity)
        {
            ISession session = SessionFactoryUtils.GetSession(SessionFactory, false);
            session.FlushMode = FlushMode.Auto;
            HibernateTemplate.SaveOrUpdate(entity);
            session.Flush();

            return entity;
        }

        /// <summary>
        /// Loads all albums
        /// </summary>
        /// <returns></returns>
        public IList<BaseEntity> FindAll()
        {
            return HibernateTemplate.LoadAll<BaseEntity>();

        }


        /// <summary>
        /// Deletes album
        /// </summary>
        /// <param name="album"></param>
        public void Delete(BaseEntity entity)
        {
            ISession session = SessionFactoryUtils.GetSession(SessionFactory, false);
            session.FlushMode = FlushMode.Auto;
            HibernateTemplate.Delete(entity);
            session.Flush();
        }
	}
}
